import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/login' //重定向到登录页
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/Login.vue'),
  },
  {
    path: '/register',
    name: 'Register',
    component: () => import('../views/Register.vue'),
  },
  {
    path: '/userenter',
    name: 'UserEnter',
    component: () => import('../views/UserEnter/UserEnter.vue')
  },
  // 线路管理
  {
    path: '/circuit',
    name: 'Circuit',
    component: () => import('../views/Circuit/Circuit.vue'),
    redirect: '/circuit/circuitindex',
    children: [
      {
        path: 'circuitindex',
        name: 'CircuitIndex',
        component: () => import('../views/Circuit/CircuitIndex.vue')
      },
      {
        path: '/circuit/circuitdetails',
        name: 'circuitDetails',
        component: () => import('@/components/CircuitDetails.vue')
      }
    ]
  },
  // 分销管理
  {
    path: '/distribution',
    name: 'DistributionIndex',
    component: () => import('../views/Distribution/DistributionIndex.vue'),
    redirect: '/distribution/districircuit',
    children: [
      {
        path: 'districircuit',
        name: 'DistriCircuit',
        component: () => import('../views/Distribution/DistriCircuit.vue')
      },
      {
        path: 'ditchadmin',
        name: 'DitchAdmin',
        component: () => import('../views/Distribution/DitchAdmin.vue')
      },
      {
        path: 'ditchaudit',
        name: 'DitchAudit',
        component: () => import('../views/Distribution/DitchAudit.vue')
      },
      {
        path: 'mydistri',
        name: 'MyDistri',
        component: () => import('../views/Distribution/MyDistri.vue')
      },
      {
        path: 'distriadmin',
        name: 'DistriAdmin',
        component: () => import('../views/Distribution/DistriAdmin.vue')
      },
      {
        path: 'circuitDetails',
        name: 'distriDetails',
        component: () => import('@/components/CircuitDetails.vue')
      },
      // 作为渠道方 详情
      {
        path: 'distributiondetails',
        name: 'DistributionDetails',
        component: () => import('../views/Distribution/DistributionDetails.vue')
      }

    ]
  },
  // 导游管理
  {
    path: '/tourguide',
    name: 'TourGuide',
    component: () => import('../views/TourGuide/TourGuideIndex.vue'),
    redirect: '/tourguide/coopguide',
    children: [
      {
        path: 'tourguideaudit',
        name: 'TourGuideAudit',
        component: () => import('../views/TourGuide/TourGuideAudit.vue'),
      },
      {
        path: 'coopguide',
        name: 'CoopGuide',
        component: () => import('../views/TourGuide/CoopGuide.vue'),
        children: [
          {
            path: 'guidedetails',
            name: 'GuideDetails',
            component: () => import('../views/TourGuide/GuideDetails.vue'),
          }
        ]
      },

    ]
  },
  {
    path: '/order',
    name: 'Order',
    component: () => import('../views/Order/OrderIndex.vue'),
  },
  // 资产管理
  {
    path: '/asset',
    name: 'Asset',
    component: () => import('../views/Asset/AssetIndex.vue'),
    redirect: '/asset/overview',
    children: [
      {
        path: 'overview',
        name: 'OverView',
        component: () => import('../views/Asset/OverView.vue'),
      },
      {
        path: 'assetrecord',
        name: 'AssetRecord',
        component: () => import('../views/Asset/AssetRecord.vue'),
      },
      {
        path: 'withdraw',
        name: 'Withdraw',
        component: () => import('../views/Asset/Withdraw.vue'),
      },

    ]
  },
  // 基础设置
  {
    path: '/setting',
    name: 'Setting',
    component: () => import('../views/Setting/SettingIndex.vue'),
  }
]

const router = new VueRouter({
  linkActiveClass: "active",
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

// router.beforeEach((to, from, next) => {
//   /**
//    * 未登录则跳转到登录页
//    * requireAuth字段 是否需要登录
//    */
//   if (to.matched.some((auth) => auth.meta.requireAuth)) {
//     let token = localStorage.getItem("token");
//     if (token) {
//       next();
//     } else {
//       next({
//         path: "/login"
//       });
//     }
//   } else {
//     next();
//   }
// })

const routerPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(error => error)
}


export default router
